package com.cow.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cow.service.AdminService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;

/**
 * @author 光环and鬼泣
 * @version 2018年5月30日 上午10:06:48
 */
@Api(description="管理员接口")
@Controller
public class AdminController {

	@Autowired
	private AdminService adminService;

	@ApiOperation(value = "管理员登录", notes = "管理员登录")
	@ResponseBody
	@RequestMapping(value = "/adminLogin.action", method = RequestMethod.POST)
	public JSONObject adminLogin(HttpServletRequest req, HttpServletResponse rep,
			@RequestParam("usernamepassword") String usernamepassword) throws Exception {
		JSONObject object = JSONObject.fromObject(usernamepassword);
		String username = object.getString("username");
		String password = object.getString("password");
		JSONObject data = new JSONObject();

		boolean result = adminService.login(username, password);
		if (result) {
			data.put("result", "登录成功");
			data.put("code", "1");
		} else {
			data.put("result", "登录失败");
			data.put("code", "-1");
		}
		return data;
	}
}
